package com.sdy.kzyy.biz.mapper;

import com.sdy.kzyy.biz.dto.OrderRecordInfoDTO;
import com.sdy.kzyy.biz.dto.OrderRecordDTO;
import com.sdy.kzyy.biz.dto.RecordInfoDTO;
import com.sdy.kzyy.biz.model.OrderRecord;
import com.sdy.mvc.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zzq
 * @since 2020-03-03
 */
public interface OrderRecordMapper extends BaseMapper<OrderRecord> {

    Integer getOrderNumber (@Param("storeCode") String storeCode, @Param("orderStatus") String orderTime);
    /**
     * 扫描二维码获取预约信息
     * @param token
     * @return
     */
    OrderRecordInfoDTO getOrderRecordInfo(String token);

    /**
     * 获取个人的所有预约记录
     * @param userId 登陆账号id
     * @return
     */
    List<OrderRecordDTO> getSelfOrderAll(@Param("userId") Integer userId);
    /**
     * 根据预约订单id查询预约详情信息
     *
     * @param id
     * @return
     */
    @Select("select r.id,\n" +
            "       p.`name`,\n" +
            "       p.card as card_id,\n" +
            "       r.order_time,\n" +
            "       r.qrcode_path,\n" +
            "       r.receive_status,\n" +
            "       r.order_status, \n" +
            "       r.receive_time,\n" +
            "       s.name as s_name,\n" +
            "       s.address,\n" +
            "       s.appoint_time,\n" +
            "       s.week,\n" +
            "       s.week_time,\n" +
            "       a.name as a_name\n" +
            "from personal_information p\n" +
            "left join order_record r\n" +
            "on p.card = r.order_card and p.user_id = r.user_id\n" +
            "left join store s\n" +
            "on r.order_store_code = s.store_code\n" +
            "left join area a\n" +
            "on s.area_code = a.code\n" +
            "where r.id = #{id}")
    RecordInfoDTO getRecordInfoById(Integer id);

}
